# -*- coding=utf-8-*-
"""
@File:memory_selection
@Author:Created by Han X.Y
@Date:on 2021/8/6 9:32 
"""

def myHash(data,hashLength):
    """
    除法取余法实现的哈希函数
    Args:
        data:
        hashLength:

    Returns:

    """
    return data%hashLength


def searchHash(hash,hashLength,data):
    """
    哈希表检索
    Args:
        hash:
        hashLength:
        data:

    Returns:

    """
    hashAddress=myHash(data,hashLength)
    #指定hashAdress存在，但并非关键值，则用开放寻址法求解
    while hash.get(hashAddress) and hash[hashAddress]!=data:
        hashAddress+=1
        hashAddress%=hashLength
    if hash.get(hashAddress)==None:
        return None
    return hashAddress
